import { successResponse, errorResponse } from 'server/utils/response'
import { Tag } from 'server/models/Tag'

export default defineEventHandler(async (event) => {
  try {
    const tags = await Tag.getPopularTags()
    
    const result = tags.map(tag => ({
      id: tag.id,
      name: tag.name,
      slug: tag.slug,
      color: tag.color || '#1890ff',
      postCount: tag.post_count || 0
    }))
    
    return successResponse(result, '获取标签列表成功')
  } catch (error) {
    console.error('获取标签列表失败:', error)
    return errorResponse('获取标签列表失败')
  }
})